package com.kx.center.common;

import java.util.HashMap;

// 共用数据缓存
public class Cache {
	
	public static String TYPE = "type";
	public static String GOODS = "goods";
	public static String STORE = "store";
	public static String TOKEN = "token";
	public static String ACCOUNT = "account";
	public static String APPACCOUNT = "appAccount";
	
	public static HashMap<String, HashMap<Object, Object>> __cache = new HashMap<String, HashMap<Object, Object>>();
	
	private static HashMap<Object, Object> getCache(String type) {

		HashMap<Object, Object> cache = __cache.get(type);
		
		if(cache == null) {
			cache = new HashMap<Object, Object>();
			__cache.put(type, cache);
		}
		
		return cache;
	}
	
	public static void set(String type, Object key, Object value) {
		HashMap<Object, Object> cache = getCache(type);
		
		if(cache.containsKey(key))
			cache.remove(key);
		cache.put(key, value);
	}
	
	public static Object get(String type, Object key) {
		HashMap<Object, Object> cache = getCache(type);
		return cache.get(key);
	}
	
	public static Boolean exists(String type, Object key) {
		HashMap<Object, Object> cache = getCache(type);
		return cache.containsKey(key);
	}
	
	public static void clean() {
		__cache.clear();
	}
	
}
